#include "util.h"

#include <windows.h>

namespace Hope {
    void SplitPath(const std::string & path, std::string & dir, std::string & name)
    {
        auto pos_back = path.find_last_of('/');
        auto pos_forward = path.find_last_of('\\');
        auto pos = pos_back == std::string::npos ? pos_forward : pos_back;
        if (pos == std::string::npos)
        {
            name = path;
            dir = "";
            return;
        }

        name = path.substr(pos + 1, std::string::npos);
        dir = path.substr(0, pos);
    }

    bool StringConvert(const std::string & src, std::wstring & dest)
	{
		std::uint32_t nLen = src.length();
		int result = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src.c_str(), nLen, (LPWSTR)dest.c_str(), nLen);
		if (result == 0) 
		{
			return false;
		}

		return true;
	}


	bool StringConvert(std::wstring &src, const std::string &dest)
	{
		std::uint32_t nLen = src.length();
		int result = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)dest.c_str(), nLen, (LPSTR)src.c_str(), nLen, NULL, NULL);
		if (result == 0)
		{
			return false;
		}

		return true;
	}

}
